<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/static/js/app/pay/jquery.min.js"></script>
    <title>支付宝提现</title>
    <script src="/static/js/app/pay/common.js"></script>
    <script src="/static/js/app/pay/util.js"></script>
    <script src="/static/js/app/pay/init.js"></script>
    <!--<script src="../rem.js"></script>-->
    <script src="/static/js/app/pay/rem-1.js"></script>
    <link rel="stylesheet" href="commom.css?v=1">
    <style>
        *{margin: 0;padding: 0;}
        .zfb-top>b{font-weight: normal;font-size: 0.24rem;color: #fff;float: right;margin-top: 0.3rem;margin-right: 0.3rem;}
        .zfbforward .zfb-total{height:0.9rem;padding: 0.3rem 0;margin-bottom: 0.18rem;position: relative}
        .zfb-total>div{width: 3.74rem;float: left;text-align: center}
        .zfb-total .zfb-all{border-right:0.01rem dashed #999}
        .zfb-total>div>p{font-size: 0.24rem;color: #333}
        .zfb-total>div>h2{font-size: 0.4rem;color: #333;font-weight: bold}
        .zfb-sum>b{width: 1.3rem;height: 100%;line-height: 1rem;color:#333;font-size: 0.28rem;float: left;font-weight: normal;text-align: center}
        .zfb-sum>input{ font-size: 0.28rem;color: #333;outline: none;border: 0;float: left;height: 90%;line-height: 0.9rem;width: 5rem; margin-top: 0.03rem;}
        .zfb-sum>span{width: 0.28rem;height: 0.28rem;float: right;color: #fff;background: #eee;font-size: 0.28rem;text-align: center;
            line-height: 0.24rem;border-radius: 50%;margin-top: 0.36rem;margin-right: 0.2rem}
        .zfb-add{cursor: pointer}
        .zfb-add>b{float: left;width: 0.4rem;height: 0.4rem;background: url("/static/img/app/pay/add.png") no-repeat;background-size: 100% 100%;
            margin: 0.3rem;}
        .zfb-add>h3{float: left;height: 100%;line-height: 1rem;color: #333;font-size: 0.24rem;font-weight: normal}
        .zfb-add>span{width: 0.14rem;height: 0.28rem;background: url("/static/img/app/pay/chouse.png") no-repeat;background-size: 100% 100%;
        float: right;margin: 0.36rem 0.3rem;}
        .zfbforward>p{width: 100%;text-align: center;height: 0.5rem;position: relative}
        .zfbforward>p>span{color: #f05c5c;
            font-size: 0.24rem;
            display: inline-block;
            position: absolute;
            left: 3rem;
            top: 0.1rem;border-bottom: 0.01rem solid #f05c5c}
        .zfbforward .apply{width:6.9rem;height:0.9rem;color: #fff;background: #999;text-align: center;
        font-size: 0.32rem;line-height: 0.9rem;margin: 0 auto;border-radius: 0.04rem;margin-top: 1.4rem}
        .zfbforward .a-color{background: #f05c5c}
        .hide{display: none}
        .message{position: fixed;top:20%;width: 100%;height: 1rem;text-align: center;}
        .message>span{color: #fff;text-align: center;line-height: 0.5rem;border-radius: 0.04rem;background: rgba(0,0,0,0.4);
            font-size: 0.2rem;display: inline-block;margin: 0 auto;padding:0 0.5rem;}
        .add1>b{background: url("/static/img/app/pay/tab_alipay.png") no-repeat;background-size: 100% 100%;width: 0.8rem;height: 0.8rem;margin: 0.1rem}
        .tocard>h3{color: #333;font-size: 0.28rem;margin-left: 0.32rem}

        /*.add1,#add,.rule,#dismiss,.tocard,#apply{ -webkit-tap-highlight-color:transparent;}*/
        /* 遮罩层*/
        .zfbforward .zhezhao{position: absolute;width: 100%;height: 100%;background: rgba(0,0,0,0.5);
            top: 0;left: 0}
        .tanc{width:5.5rem;height: 4.8rem;border-radius: 0.1rem;background: #fff;position: absolute;top:18%;left: 50%;
            margin-left: -2.75rem;}
        .tanc>h1{width: 100%;text-align: center;color: #333;font-size: 0.36rem;line-height: 1rem;font-weight: normal}
        .tanc-input{width: 5.1rem;margin: 0 auto}
        .tanc-input>p{width: 100%;height: 0.6rem;overflow: hidden;margin-bottom: 0.3rem;line-height: 0.6rem}
        .tanc-input>p>b{font-size: 0.24rem;color: #333;font-weight: normal;width: 1rem;text-align: right;float: left;margin-right: 0.1rem}
        .tanc-input>p>input{border: 0;width: 2.3rem;height: 0.6rem;border-radius: 0.1rem;background: #eee;font-size: 0.24rem;float: left;margin-right: 0.1rem}
        .tanc-input>p>span{width: 1.5rem;height: 0.6rem;color: #fefefe;background: #f05c5c;font-size: 0.2rem;text-align: center;line-height: 0.6rem;float: right;border-radius: 0.1rem}
        .tanc-sure{font-size: 0.3rem;position: absolute;bottom: 0.3rem;left:50%;margin-left:-0.75rem;width: 1.5rem;height: 0.8rem;line-height: 0.8rem;background: #f05c5c;border-radius: 0.1rem;color: #fff;text-align: center;}
        .hide{display: none}
        .attenText{
            font-size: 0.3rem;
            padding: 0 0.2rem;
            text-align: center;
            margin-bottom: 0.3rem;
            color: #333;
            line-height: 0.4rem;
        }
        .btnss{
            width: 4rem;
            margin: 0 auto;
            overflow: hidden;
        }
        .btnss>span{
            float: left;
            font-size: 0.3rem;
            width: 1.5rem;
            height: 0.8rem;
            line-height: 0.8rem;
            background: #f05c5c;
            border-radius: 0.1rem;
            color: #fff;
            text-align: center;
        }
        #tanc-sure{
            float: right;
        }
    </style>
</head>
<body>
<script src="/static/js/common/Monitor.js"></script>
    <div class="zfbforward">
        <div class="zfb-top">
            <span class="return"></span>
            <h1>支付宝提现</h1>
            <b class="tocard">提现到银行卡</b>
        </div>
        <div class="zfb-total">
            <div class="zfb-all">
                <p>资产总额（花瓣）</p>
                <h2 id="total">--</h2>
            </div>
            <div class="zfb-ok">
                <p>可提现（元）</p>
                <h2 id="putFor">--</h2>
            </div>
        </div>
        <div class="zfb-sum">
            <b>金额</b>
            <input id="money" type="text" placeholder="请输入提现金额">
            <span id="dismiss" class="hide">×</span>
        </div>
        <div class="zfb-add" id="add">
            <b></b>
            <h3>请添加账户</h3>
            <span></span>
        </div>
        <div class="zfb-add add1 hide">
            <b></b>
            <h3>请添加账户</h3>
            <span></span>
        </div>
        <div class="zfb-add tocard">
            <h3>提现到银行卡</h3>
            <span></span>
        </div>
        <p class="rule"><span>提现规则说明</span></p>
        <div class="apply" id="apply">申请提现</div>
        <div class="zhezhao hide">
            <div class="tanc">
                <h1>验证手机号</h1>
                <p class="attenText">为了你的账号安全,需要验证手机号码才能继续操作哦</p>
                <div class="tanc-input">
                    <p>
                        <b>手机号码</b><input id="phone" type="text"><span id="vscode">获取验证码</span>
                    </p>
                    <p>
                        <b>验证码</b><input id="smsCode" type="text">
                    </p>
                </div>
                <div class="btnss">
                    <span id="tanc-cansule">取消</span>
                    <span id="tanc-sure">确定</span>
                </div>

            </div>
        </div>
    </div>
    <div class="message hide" id="message"><span></span></div>

    <script>
        var capitalAccount = null;
        $(function () {
            // 设置点击事件

            initUser();
            refreshCapitalAccount();
            capitalAccount = userobj.capitalAccount ? JSON.parse(userobj.capitalAccount) : null;
            $("#total").html(userobj.gainsBal);
            $("#putFor").html(userobj.gains);
            if(capitalAccount){
                if(capitalAccount.bankCode==1){
                    $("#add").addClass("hide");
                    $(".add1").removeClass("hide");
                    $(".add1>h3").html(capitalAccount.accountName + "(" + capitalAccount.accountNo + ")");
                    $(".add1").click(function () {
                        window.location.href=base_url+"/putForward/zfbaccount.html";
                    })
                }else{
                    $("#add").removeClass("hide");
                    $(".add1").addClass("hide");
                    $(".add1>h3").html("");
                    //修改账户
                    $("#add").click(function () {
                        window.location.href=base_url+"/putForward/zfbaccount.html";
                    });
                }
                // accountName=datalist.accountName.replace(/\s/ig,'');//去掉所有空格
                // userobj.accountName=accountName;
                // accountNo=datalist.accountNo.replace(/\s/ig,'');//去掉所有空格
            }else{
                $("#add").click(function () {
                    window.location.href=base_url+"/putForward/zfbaccount.html";
                });
            }
            //输入金额
            $("#money").on("input",function () {
                var money=$(this).val();
                if(money){
                    $("#dismiss").removeClass("hide");
                    $("#apply").addClass("a-color");
                }else if(money==""){
                    $("#dismiss").addClass("hide");
                    $("#apply").removeClass("a-color");
                }
            });
            //提现规则说明
            $(".rule").click(function () {
                window.location.href=base_url+"/putForward/rule.html";
            });
            //清空输入的金额
            $("#dismiss").click(function () {
                $("#money").val("");
                $(this).addClass("hide");
                $(".apply").removeClass("a-color");
            });
        //    提现到银行卡
            $(".tocard").click(function () {
                window.location.href=base_url+"/putForward/cardforward.html";
            });
            // 提现申请
            $("#apply").click(function () {
                var price=$("#money").val();
                if(isNaN(price)){
                    $("#message span").html("请输入数字");
                    $("#message").removeClass("hide");
                    setTimeout(function () {
                        $("#message").addClass("hide");
                    },2000);
                }else{
                    if(price<50){
                        $("#message span").html("提现金额不低于50");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }else if(50 <= price && price<=userobj.gains){
                        //提现接口
                        if(userobj.customerPhoneCheckStatus == 1){//手机号没有验证
                            $(".zhezhao").removeClass("hide");
                            // 手机号码验证
                            check(userobj.accessId,userobj.accessToken)
                        }else{// 手机号验证过
                            $(".zhezhao").addClass("hide")
                            withdraw(userobj.accessId,userobj.accessToken,price)
                        }
                    }
                    if(price>userobj.gains){
                        $("#message span").html("不可以超过可提现金额");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }
                    if(price<userobj.gains && price>5000){
                        $("#message span").html("单日提现不可以超过5000");
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }
                }

            });
            // 点击弹窗外部，弹窗消失
            $("#tanc-cansule").click(function () {
                $(".zhezhao").addClass("hide")
            })
            $(".tanc").click(function (e) {
                e.stopPropagation()
            })

        });
        function check(accessId,accessToken){
            // 获取验证码
            $("#vscode").click(function () {
                var phone=$("#phone").val();
                if(isPoneAvailable(phone)){
                    // 发送短信
                    sendSmsCode(accessId,accessToken,phone)
                }else{
                    $("#message span").html("请正确输入手机号！");
                    $("#message").removeClass("hide");
                    setTimeout(function () {
                        $("#message").addClass("hide");
                    },1000);
                }
            })
            // 确定按钮
            $("#tanc-sure").click(function () {
                var phone=$("#phone").val();
                var smsCode=$("#smsCode").val();
                if(phone && smsCode){
                    // 效验手机号
                    checkPhone(accessId,accessToken,phone,smsCode)
                }else{
                    $("#message span").html("请完善信息！");
                    $("#message").removeClass("hide");
                    setTimeout(function () {
                        $("#message").addClass("hide");
                    },1000);
                }
            })
        }
    //   提现接口
        function withdraw(accessId,accessToken,price) {
            $.ajax({
                url:genUrl("/wallet/withdraw"),
                type: 'GET',
                contentType:"application/json",
                dataType:'json',
                async:false,
                headers:{
                    "x-access-id": accessId,
                    "x-access-token": accessToken,
                    "x-ua": ua
                },
                data:{
                    "bankCode":1,
                    "price":price
                },
                success: function (res) {
                    console.log(userobj)
                    if(res.code==0){
                        userobj.withdraw = res.data.withdraw;
                        updateUser(userobj);
                        window.location.href=base_url+"/putForward/putSuccess.html";
                    }else{
                        $("#message span").html(res.message);
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },2000);
                    }
                }
            });
        }
    //   验证手机号
        function checkPhone(accessId,accessToken,phone,smsCode) {
            $.ajax({
                url:genUrl("/customer/check/checkPhone"),
                type: 'GET',
                contentType:"application/json",
                dataType:'json',
                async:false,
                headers:{
                    "x-access-id": accessId,
                    "x-access-token": accessToken,
                    "x-ua": ua
                },
                data:{
                    "phone":phone,
                    "smsCode":smsCode
                },
                success: function (res) {
                    if(res.code == 0){
                        $("#message span").html(res.message);
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },1000);
                        $(".zhezhao").addClass("hide")
                        $("#phone,#smsCode").val("");
                        // 重新刷新页面
                        initUser();
                        refreshCapitalAccount();
                    }else{
                        $("#message span").html(res.message);
                        $("#message").removeClass("hide");
                        setTimeout(function () {
                            $("#message").addClass("hide");
                        },1000);
                    }
                }
            });
        }
    //    发送短信
        function sendSmsCode(accessId,accessToken,phone) {
            $.ajax({
                url:genUrl("/system/sendSmsCode"),
                type: 'GET',
                contentType:"application/json",
                dataType:'json',
                async:false,
                headers:{
                    "x-access-id": accessId,
                    "x-access-token": accessToken,
                    "x-ua": ua
                },
                data:{
                    "mobile":phone,
                    "type":"checkPhone"
                },
                success: function (res) {
                    if(res.code != 0){
                        alert(res.message);
                        return
                    }
                    $("#message span").html("发送成功");
                    $("#message").removeClass("hide");
                    setTimeout(function () {
                        $("#message").addClass("hide");
                    },1000);
                }
            });
        }
        // 判断是否为手机号
        function isPoneAvailable(phone) {
            var myreg = /^[1][0-9][0-9]{9}$/;
            if (!myreg.test(phone)) {
                return false;
            } else {
                return true;
            }
        }
    </script>
</body>
</html>